home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Online / Term / Extras / Source / gtlayout-source.lha / LT_LockWindow.c < prev    next >
C/C++ Source or Header  |  1996-10-09  |  6KB  |  293 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1996 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14.  
  15. /*****************************************************************************/
  16.  
  17.  
  18. VOID
  19. LTP_DeleteWindowLock(LockNode *Node)
  20. {
  21.     struct Window *Window = Node->Window;
  22.  
  23.     Remove((struct Node *)Node);
  24.  
  25.     if(Window->MinWidth == Window->MaxWidth && Window->MinHeight == Window->MaxHeight && Window->Width == Window->MaxWidth && Window->Height == Window->MaxHeight)
  26.         WindowLimits(Window,Node->MinWidth,Node->MinHeight,Node->MaxWidth,Node->MaxHeight);
  27.  
  28.     EndRequest(&Node->Requester,Window);
  29.  
  30.     if(V39)
  31.         SetWindowPointerA(Window,NULL);
  32.     else
  33.         ClearPointer(Window);
  34.  
  35.     ModifyIDCMP(Window,Node->OldIDCMPFlags);
  36.  
  37.     FreeMem(Node,sizeof(LockNode));
  38. }
  39.  
  40.  
  41. /*****************************************************************************/
  42.  
  43.  
  44. /****** gtlayout.library/LT_LockWindow ******************************************
  45. *
  46. *   NAME
  47. *    LT_LockWindow -- Block user access to a window.
  48. *
  49. *   SYNOPSIS
  50. *    LT_LockWindow(Window);
  51. *                    A0
  52. *
  53. *    VOID LT_LockWindow(struct Window *);
  54. *
  55. *   FUNCTION
  56. *    The window will get a wait mouse pointer attached and a blank
  57. *    Requester, preventing any user gadgets from getting used. The
  58. *    window minimum and maximum sizes are set to the current window
  59. *    size so the user will be unable to resize the window or click
  60. *    on the zoom gadget.
  61. *
  62. *    This routine nests, multiple calls to LT_LockWindow() using the
  63. *    same window will increment a usage counter, so exactly the
  64. *    same number of calls to LT_UnlockWindow() will be required to
  65. *    unlock the window.
  66. *
  67. *   INPUTS
  68. *    Window - Pointer to window structure; passign NULL is harmless.
  69. *
  70. *   RESULT
  71. *    none
  72. *
  73. *   NOTES
  74. *    Do not close the window you have locked unless all the
  75. *    outstanding locks are freed or memory will be lost which
  76. *    can never be reclaimed. Before you close the window,
  77. *    call gtlayout.library/LT_DeleteWindowLock.
  78. *
  79. *   SEE ALSO
  80. *    gtlayout.library/LT_DeleteWindowLock
  81. *
  82. ******************************************************************************
  83. *
  84. */
  85.  
  86. VOID LIBENT
  87. LT_LockWindow(REG(a0) struct Window *window)
  88. {
  89.     if(window)
  90.     {
  91.         LockNode    *lockNode;
  92.         BOOL          found;
  93.  
  94.         found = FALSE;
  95.  
  96.         ObtainSemaphore(<P_LockSemaphore);
  97.  
  98.         SCANLIST(<P_LockList,lockNode)
  99.         {
  100.             if(lockNode->Window == window)
  101.             {
  102.                 lockNode->Count++;
  103.  
  104.                 found = TRUE;
  105.  
  106.                 break;
  107.             }
  108.         }
  109.  
  110.         if(!found)
  111.         {
  112.             if(lockNode = AllocMem(sizeof(LockNode),MEMF_PUBLIC | MEMF_ANY | MEMF_CLEAR))
  113.             {
  114.                 AddTail((struct List *)<P_LockList,(struct Node *)lockNode);
  115.  
  116.                 lockNode->Window        = window;
  117.                 lockNode->OldIDCMPFlags    = window->IDCMPFlags;
  118.                 lockNode->Count            = 1;
  119.                 lockNode->MinWidth        = window->MinWidth;
  120.                 lockNode->MaxWidth        = window->MaxWidth;
  121.                 lockNode->MinHeight        = window->MinHeight;
  122.                 lockNode->MaxHeight        = window->MaxHeight;
  123.  
  124.                 WindowLimits(window,window->Width,window->Height,window->Width,window->Height);
  125.  
  126.                 Request(&lockNode->Requester,window);
  127.  
  128.                 /* Now, this needs a bit of explanation. The requester will shut down
  129.                  * menu processing for this window and still we enable IDCMP_MENUPICK.
  130.                  * This is done in order to avoid setting the IDCMP flags to 0. One
  131.                  * side-effect of setting the IDCMP flags to 0 is that the window message
  132.                  * queue will be cleared, which can be undesirable in certain cases.
  133.                  * With the menu strip blocked IDCMP_MENUPICK cannot do any harm.
  134.                  */
  135.  
  136.                 ModifyIDCMP(window,IDCMP_MENUPICK | (window->IDCMPFlags & (IDCMP_REFRESHWINDOW|IDCMP_CHANGEWINDOW)));
  137.  
  138.                 if(V39)
  139.                 {
  140.                     STATIC struct TagItem tags[3] =
  141.                     {
  142.                         WA_BusyPointer,        TRUE,
  143.                         WA_PointerDelay,    TRUE,
  144.  
  145.                         TAG_DONE
  146.                     };
  147.  
  148.                     SetWindowPointerA(window,tags);
  149.                 }
  150.                 else
  151.                 {
  152.                     STATIC UWORD __chip Stopwatch[(1 + 16 + 1) * 2] =
  153.                     {
  154.                         0x0000,0x0000,
  155.  
  156.                         0x0400,0x07C0,
  157.                         0x0000,0x07C0,
  158.                         0x0100,0x0380,
  159.                         0x0000,0x07E0,
  160.                         0x07C0,0x1FF8,
  161.                         0x1FF0,0x3FEC,
  162.                         0x3FF8,0x7FDE,
  163.                         0x3FF8,0x7FBE,
  164.                         0x7FFC,0xFF7F,
  165.                         0x7EFC,0xFFFF,
  166.                         0x7FFC,0xFFFF,
  167.                         0x3FF8,0x7FFE,
  168.                         0x3FF8,0x7FFE,
  169.                         0x1FF0,0x3FFC,
  170.                         0x07C0,0x1FF8,
  171.                         0x0000,0x07E0,
  172.  
  173.                         0x0000,0x0000
  174.                     };
  175.  
  176.                     SetPointer(window,Stopwatch,16,16,-6,0);
  177.                 }
  178.             }
  179.         }
  180.  
  181.         ReleaseSemaphore(<P_LockSemaphore);
  182.     }
  183. }
  184.  
  185.  
  186. /****************************************************************************/
  187.  
  188.  
  189. /****** gtlayout.library/LT_UnlockWindow ******************************************
  190. *
  191. *   NAME
  192. *    LT_UnlockWindow -- The complement to LT_LockWindow().
  193. *
  194. *   SYNOPSIS
  195. *    LT_UnlockWindow(Window);
  196. *                      A0
  197. *
  198. *    VOID LT_UnlockWindow(struct Window *);
  199. *
  200. *   FUNCTION
  201. *    This routine unlocks a window locked using LT_LockWindow, freeing
  202. *    allocated memory, restoring the window characteristics to their
  203. *    original values.
  204. *
  205. *   INPUTS
  206. *    Window - Pointer to window structure; passing NULL is harmless.
  207. *
  208. *   RESULT
  209. *    none
  210. *
  211. *   SEE ALSO
  212. *    gtlayout.library/LT_LockWindow
  213. *
  214. ******************************************************************************
  215. *
  216. */
  217.  
  218. VOID LIBENT
  219. LT_UnlockWindow(REG(a0) struct Window *window)
  220. {
  221.     if(window)
  222.     {
  223.         LockNode *lockNode;
  224.  
  225.         ObtainSemaphore(<P_LockSemaphore);
  226.  
  227.         SCANLIST(<P_LockList,lockNode)
  228.         {
  229.             if(lockNode->Window == window)
  230.             {
  231.                 if(--lockNode->Count < 1)
  232.                     LTP_DeleteWindowLock(lockNode);
  233.  
  234.                 break;
  235.             }
  236.         }
  237.  
  238.         ReleaseSemaphore(<P_LockSemaphore);
  239.     }
  240. }
  241.  
  242.  
  243. /*****************************************************************************/
  244.  
  245.  
  246. /****** gtlayout.library/LT_DeleteWindowLock ******************************************
  247. *
  248. *   NAME
  249. *    LT_DeleteWindowLock -- Remove all locks from a window
  250. *
  251. *   SYNOPSIS
  252. *    LT_DeleteWindowLock(Window);
  253. *                          A0
  254. *
  255. *    VOID LT_DeleteWindowLock(struct Window *);
  256. *
  257. *   FUNCTION
  258. *    Before closing a locked window you should call this routine
  259. *    which will remove all outstanding locks from it.
  260. *
  261. *   INPUTS
  262. *    Window - Pointer to window structure; passing NULL is
  263. *    harmless.
  264. *
  265. *   RESULT
  266. *    none
  267. *
  268. ******************************************************************************
  269. *
  270. */
  271.  
  272. VOID LIBENT
  273. LT_DeleteWindowLock(REG(a0) struct Window *window)
  274. {
  275.     if(window)
  276.     {
  277.         LockNode *lockNode;
  278.  
  279.         ObtainSemaphore(<P_LockSemaphore);
  280.  
  281.         SCANLIST(<P_LockList,lockNode)
  282.         {
  283.             if(lockNode->Window == window)
  284.             {
  285.                 LTP_DeleteWindowLock(lockNode);
  286.                 break;
  287.             }
  288.         }
  289.  
  290.         ReleaseSemaphore(<P_LockSemaphore);
  291.     }
  292. }
  293.